home *** CD-ROM | disk | FTP | other *** search
/ Programming a Multiplayer FPS in DirectX / Programming a Multiplayer FPS in DirectX (Companion CD).iso / DirectX / dxsdk_oct2004.exe / dxsdk.exe / Documentation / DirectX9 / directx9_m.chm / directx / code / browdata.js < prev    next >
Encoding:
JavaScript  |  2004-09-30  |  2.2 KB  |  53 lines

  1. // -----------------------------------------------------------
  2. // BrowserData() constructor
  3. // .userAgent: (string) the HTTP_USER_AGENT input string
  4. // .browser: (string) "MSIE", "Opera", "Nav", "Other"
  5. // .majorVer: (integer) major version
  6. // .minorVer: (string) minor (dot) version
  7. // .betaVer: (string) beta version
  8. // .platform: (string) operating system
  9. // .getsNavBar (boolean) whether browser gets the DHTML menus
  10. // .doesActiveX (boolean) whether browser does 32-bit ActiveX
  11. // -----------------------------------------------------------
  12.  
  13. function BrowserData(sUA)
  14. {
  15.     this.userAgent = sUA.toString();
  16.     var rPattern = /(MSIE)\s(\d+)\.(\d+)((b|p)([^(s|;)]+))?;?(.*(98|95|NT|3.1|32|Mac|X11))?\s*([^\)]*)/;
  17.     if (this.userAgent.match(rPattern))
  18.     {
  19.         this.browser = "MSIE";
  20.         this.majorVer = parseInt(RegExp.$2) || 0;
  21.         this.minorVer = RegExp.$3.toString() || "0";
  22.         this.betaVer = RegExp.$6.toString() || "0";
  23.         this.platform = RegExp.$8 || "Other";
  24.         this.platVer = RegExp.$9 || "0";
  25.     }
  26.     else if (this.userAgent.match(/Mozilla[/].*(95[/]NT|95|NT|98|3.1).*Opera.*(\d+)\.(\d+)/))
  27.     {
  28.         //"Mozilla/4.0 (Windows NT 5.0;US) Opera 3.60  [en]";
  29.         this.browser = "Opera";
  30.         this.majorVer = parseInt(RegExp.$2) || parseInt(RegExp.$2) || 0;
  31.         this.minorVer = RegExp.$3.toString() || RegExp.$3.toString() || "0";
  32.         this.platform = RegExp.$1 || "Other";
  33.     }
  34.     else if (this.userAgent.match(/Mozilla[/](\d*)\.?(\d*)(.*(98|95|NT|32|16|68K|PPC|X11))?/))
  35.     {
  36.         //"Mozilla/4.5 [en] (WinNT; I)"
  37.         this.browser = "Nav";
  38.         this.majorVer = parseInt(RegExp.$1) || 0;
  39.         this.minorVer = RegExp.$2.toString() || "0";
  40.         this.platform = RegExp.$4 || "Other";
  41.     }
  42.     else
  43.     {
  44.         this.browser = "Other";
  45.     }
  46.     this.getsNavBar = ("MSIE" == this.browser && 4 <= this.majorVer && "Mac" != this.platform && "X11" != this.platform);
  47.     this.doesActiveX = ("MSIE" == this.browser && 3 <= this.majorVer && ("95" == this.platform || "98" == this.platform || "NT" == this.platform));
  48.     this.fullVer = parseFloat( this.majorVer + "." + this.minorVer );
  49.     this.doesPersistence = ("MSIE" == this.browser && 5 <= this.majorVer && "Mac" != this.platform && "X11" != this.platform);
  50. }
  51.  
  52. var oBD = new BrowserData(window.navigator.userAgent);
  53.